﻿using DNT.RavenQA.Core.Models;
using Raven.Client;

namespace DNT.RavenQA.Web.Infrastructure.Commands
{
    public class AddAnswerCommand : RavenCommand<IAnswerInput, VoidResult>
    {
        private readonly IAnswerInput _parameter;

        public AddAnswerCommand(IAnswerInput parameter)
            : base(parameter)
        {
            _parameter = parameter;
        }

        public override VoidResult Execute(IDocumentSession session)
        {
            _parameter.Question.AddAnswer(() =>
                                              {
                                                  var answer = Answer.New(_parameter);
                                                  session.Store(answer);
                                                  return answer;
                                              });
            return VoidResult.Instance;
        }
    }
}